<admintpl file="header" />
<link rel="stylesheet" href="__PUBLIC__/js/jquery-ui-1.12/jquery-ui.css" />
<link rel="stylesheet" href="__PUBLIC__/js/sco.js/css/scojs.css" />
</head>
<style>
.tooltip{
	width: 319px;
}
</style>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('index')}">员工信息</a></li>
			<li class="active"><a href="{:U('add')}">添加信息</a></li>
		</ul>
		<form action="{:U('add')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th width="80">姓名</th>
							<td>
								<input type="text" style="width: 400px;" name="post[ep_name]" id="title" value="" placeholder=""/>
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th width="80">性别</th>
							<td>
								<foreach name='sex' item='vo' key='k'>
									<label for="sex{$k}" class='radio inline'><input type="radio" value='{$k}' id='sex{$k}' name='post[sex]' {$k == 1 ? checked : ''} />{$vo}</label>
								</foreach>
							</td>
						</tr>						
						<tr>
							<th width="80">员工编号</th>
							<td>
								系统自动生成~~
								<!-- <input type="text" style="width: 400px;" name="post[sn]" id="sn" value=" " placeholder=""/> -->
							</td>
						</tr>
						<tr>
							<th width="80">入职日期</th>
							<td>
								<input type="text" style="width: 400px;" name="post[join_date]" class="js-date" value=""  autocomplete="off">
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>部门</th>
							<td>
								<select style="width: 400px;" id='department' name="post[department_id]">
									<option value="">请选择部门</option>
									{:select_department()}
								</select>
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>团队主管</th>
							<td id='leader'>
								{$leader.ep_name}
							</td>
							<input type="hidden" style="width: 400px;" name="post[leader_id]" id="leader_id" value="{$approver.ep_id}" placeholder=""/>
						</tr>
						<tr>
							<th>上级审核人</th>
							<td>
								<input type="text" style="width: 200px;"  id="input_name" value="{$approver.ep_name}" placeholder=""/>
								<input type="hidden" style="width: 400px;" name="post[approver_id]" id="approver_id" value="{$approver.ep_id}" placeholder=""/>
								<!-- <a href="JavaScript:;" class="btn btn-primary btn-small" id='clear_leader'>审核权力交由行政管理员代理</a> -->
							</td>
						</tr>
						
						<tr>
							<th>职位</th>
							<td>
								<input type="text" id='position' name="post[position_name]" value=""  />
							</td>
						</tr>
						<tr>
							<th>职级类型</th>
							<php>
								
							</php>
							<td>
								<foreach name='positionLvl' item='vo' key='k'>
									<label for="positionLvl{$k}" class='radio inline'><input type="radio" value='{$k}' id='positionLvl{$k}' name='post[position_lvl_id]' />{$vo}</label>
								</foreach>
							</td>
						</tr>
						<tr>
							<th>手机</th>
							<td><input type="text" style="width: 400px;" name="post[phone]" id="title" value="" placeholder=""/></td>
						</tr>
						<tr>
							<th>邮箱</th>
							<td>
								<input type="text" style="width: 400px;" name="post[email]" id="title" value="" placeholder=""/>
							</td>
						</tr>
						<tr>
							<th>状态</th>
							<td>
								<foreach name='userStatus' item='vo' key='k'>
									<label for="userStatus{$k}" class='radio inline'><input type="radio" value='{$k}' id='userStatus{$k}' name='post[status]' {$k == 1 ? checked : ''} />{$vo}</label>
								</foreach>
							</td>
						</tr>
						<tr>
							<th>特权</th>
							<td>
								<foreach name='privilege' item='vo' key='k' >
									<label for="privilege{$k}" class='checkbox' >
									<input type="checkbox" value='{$k}' id='privilege{$k}' name='post[privilege][]'  <?php echo (in_array($k,$info[privilege]) ? checked : ''); ?> />
									<span data-trigger={$vo['rule'] ? "tooltip" : '' } data-content="{:implode('<br/>',$vo['rule'])}">{$vo.name}</span></label>
								</foreach>
							</td>
						</tr>						
						<tr>
							<th>
								<span data-trigger="tooltip" data-content="无需打卡<br/>月结导数据，全勤状态">是否免打卡</span>
							</th>
							<td>
								<foreach name='isAttendance' item='vo' key='k'>
									<label for="isAttendance{$k}" class='radio inline'>
									<input type="radio" value='{$k}' id='isAttendance{$k}' name='post[is_attendance]' {$k == 1 ? checked : ''} />{$vo}</label>
								</foreach>
							</td>
						</tr>						
						<tr>
							<th>备注</th>
							<td>初始密码：abc123</td>
						</tr>						
					</table>
				</div>
				<div class="span3">
					<table class="table table-bordered">
						<tr>
							<th>个人照片</th>
						</tr>
						<tr>
							<td>
								<div style="text-align: center;">
									<input type="hidden" name="smeta[thumb]" id="thumb" value="">
									<a href="javascript:void(0);" onclick="flashupload('thumb_images', '附件上传','thumb',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">
										<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="thumb_preview" width="135" style="cursor: hand"/>
									</a>
									<input type="button" class="btn btn-small" onclick="$('#thumb_preview').attr('src','__TMPL__Public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;" value="取消图片">
								</div>
							</td>
						</tr>
						<tr>
							<th>发布时间</th>
						</tr>
						<tr>
							<td><input type="text" name="post[post_modified]" value="{:date('Y-m-d H:i:s',time())}" class="js-datetime"></td>
						</tr>
						<tr>
							<th>状态</th>
						</tr>
						<tr>
							<td>
								<label class="radio"><input type="radio" name="post[post_status]" value="1" checked>审核通过</label>
								<label class="radio"><input type="radio" name="post[post_status]" value="0">待审核</label>
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">{:L('ADD')}</button>
				<a class="btn" href="{:U('index')}">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery-ui-1.12/jquery-ui.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/sco.js/js/sco.tooltip.js"></script>
	<script type="text/javascript">
	$('#clear_leader').click(function(){
		$('#approver_id').val('0');
		$('#input_name').val('0');
	})
	
	function autoAfter(e,ui){
		$('#approver_id').val(ui.item.value.ep_id);
	}
	//-----------职位----
	$('#position').autocomplete({
		source: function( request, response ) {
	          $.getJSON( "{:U('AdminPosition/findName')}", {
	            name: request.term
	          },function(data){
	        	  var _posnameAry = $.map(data.info,function(item){
	        		  return {
	        			label:item  
	        		  };
	        	  });
	        	  
	        	  response(_posnameAry); 
	          })
		}
    });
	$('#sn_auto').click(function(){
		$.post("{:U('sn_auto')}",function(ret){
			$('#sn').attr('value',ret.sn)
		})
	})
	
	//---------根据部门选择领导--------
	$('#department').change(function(){
		var _depid = $(this).val();
		$.post("{:U('getLeader')}",{dep_id:_depid},function(ret){
			if (!ret.status) {
				opendialog('error','数据获取错误');
			}
			var _list = ret.info;
			$('#leader').empty();
			$('#leader').text(_list.ep_name);
			$('#input_name').attr('value',_list.ep_name);
			$('#approver_id').val(_list.ep_id);
			$('#leader_id').val(_list.ep_id);
		});
	})
	
	
	
		$(function() {
			$(".js-ajax-close-btn").on('click', function(e) {
				e.preventDefault();
				Wind.use("artDialog", function() {
					art.dialog({
						id : "question",
						icon : "question",
						fixed : true,
						lock : true,
						background : "#CCCCCC",
						opacity : 0,
						content : "您确定需要关闭当前页面嘛？",
						ok : function() {
							setCookie("refersh_time", 1);
							window.close();
							return true;
						}
					});
				});
			});
			/////---------------------
			Wind.use('validate','ajaxForm','artDialog',function() {
				
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input
								.attr('placeholder')) {
							input.val('');
						}
					});
				}
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap,errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {}
					},
					//验证规则
					rules : {
						'post[ep_name]' : {required : 1},
						'post[department_id]' : {required : 1},
						'post[position_lvl_id]' : {required : 1},
						'post[email]' : {required : 1},
						'post[sn]' : {required : 1},
						'post[join_date]' : {required : 1},
						'post[leader_id]' : {required : 1},
					},
					//验证未通过提示消息
					messages : {
						'post[ep_name]' : {required : '请输入姓名'},
						'post[department_id]' : {required : '请选择部门'},
						'post[email]' : {required : '请填写邮箱'},
						'post[position_lvl_id]' : {required : '请选择职级'},
						'post[sn]' : {required : '请填写员工编号'},
						'post[join_date]' : {required : '请填写入职日期'},
						'post[leader_id]' : {required : '请填写入审核人'},
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr,$form,options) {
	
							},
							success : function(data,statusText,xhr,$form) {
								if (data.status) {
									setCookie("refersh_time",1);
									//添加成功
									Wind.use("artDialog",function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [
											{
												name : '继续添加？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											},
											{
												name : '返回列表',
												callback : function() {
													location.href = "{:U('index')}";
													return true;
												}
											}
											]
										});
									});
								} else {
									art.dialog({
										id : 'error',
										icon : 'error',
										lock : true,
										fixed : true,
										background : "#CCCCCC",
										opacity : 0,
										content : data.info,
										cancelVal : '确定',
										cancel : function() {
											
										}
									});
								}
							}
						});
					}
				});
			});
		////-------------------------
		});
	</script>
</body>
</html>